//
//  HomeFocusModel.m
//  LoveFreshBeen
//
//  Created by huodian on 16/10/15.
//  Copyright © 2016年 魏根. All rights reserved.
//

#import "HomeFocusModel.h"

#import "NetWorkingTool.h"

@implementation HomeFocusModel

-(instancetype)initWithDict:(NSDictionary*)dict
{
    if (self == [super init])
    {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
    
    
}

+(instancetype)modelWithDict:(NSDictionary*)dict
{
    return [[self alloc]initWithDict:dict];
    
    
}
+(void)downLoadTheMessage:(NSString*)key andFinish:(void (^)(NSArray *))finishBlock andError:(void (^)())errorBlock
{
    NetWorkingTool* tool = [NetWorkingTool shareInstance];
    
    NSDictionary* paramars = tool.params;
    
//    NSMutableDictionary* dict = [[NSMutableDictionary alloc]init];
    
    [[NetWorkingTool shareInstance] getDatawithParam:@"1" WithUrlString:paramars[@"1"] withSuccessBlock:^(NSDictionary* data) {
        
        
        NSMutableArray* modelArray = [[NSMutableArray alloc]init];
       
        NSDictionary* dictData = data[@"data"];
        
        NSArray* focusArray = dictData[key];
        
        
        for (NSDictionary* dict in focusArray) {
            
            HomeFocusModel* model = [[HomeFocusModel alloc]initWithDict:dict];
            
            if ([key isEqualToString:@"focus"]) {
                
                [modelArray addObject:model];
                
            }else if([key isEqualToString:@"icons"])
            {
                
                [modelArray addObject:model];
                
                
                
            }else
            {
                [modelArray addObject:model];
                
              
                
            }
            
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            
             finishBlock(modelArray);
        });
       
       
       
    } withFailedBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        errorBlock();
        
    } withErrorBlock:^(NSString *message) {
        
        NSLog(@"%@",message);
        
    }];
    
    
    
    
}



@end
